package com.sx.pipeline.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.sx.pipeline.R
import com.sx.pipeline.repos.http.res.BannerVO
import com.youth.banner.adapter.BannerAdapter
import com.youth.banner.util.BannerUtils

/**
 * @Author: YY
 * @Date: 2022/5/19
 * @Description: TODO
 */
class HomeBannerAdapter(dataList: MutableList<BannerVO>): BannerAdapter<BannerVO, HomeBannerAdapter.ImageHolder>(dataList) {

    class ImageHolder(view: View) : RecyclerView.ViewHolder(view) {
        var imageView: ImageView = view as ImageView
    }

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): ImageHolder {
        val imageView = BannerUtils.getView(parent, R.layout.view_banner_image) as ImageView
        //通过裁剪实现圆角
        BannerUtils.setBannerRound(imageView, 25f)
        return ImageHolder(imageView)
    }

    override fun onBindView(holder: ImageHolder?, data: BannerVO, position: Int, size: Int) {
        Glide.with(holder!!.itemView)
            .load(data.imageUrl)
            .skipMemoryCache(true)
            .diskCacheStrategy(DiskCacheStrategy.NONE)
            .into(holder.imageView)
    }
}